package com.eshop.modules.template.service.impl;

import java.io.IOException;
import java.util.Iterator;
import com.eshop.utils.FileUtil;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.template.service.dto.ShippingTemplatesFreeDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.template.service.dto.ShippingTemplatesFreeQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.template.service.ShippingTemplatesFreeService;
import com.eshop.modules.template.domain.ShippingTemplatesFree;
import com.eshop.modules.template.service.mapper.ShippingTemplatesFreeMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class ShippingTemplatesFreeServiceImpl extends BaseServiceImpl<ShippingTemplatesFreeMapper, ShippingTemplatesFree> implements ShippingTemplatesFreeService
{
    private final IGenerator generator;
    
    public Map<String, Object> queryAll(final ShippingTemplatesFreeQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<ShippingTemplatesFree> page = (PageInfo<ShippingTemplatesFree>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)ShippingTemplatesFreeDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<ShippingTemplatesFree> queryAll(final ShippingTemplatesFreeQueryCriteria criteria) {
        return (List<ShippingTemplatesFree>)((ShippingTemplatesFreeMapper)this.baseMapper).selectList((Wrapper)QueryHelpPlus.getPredicate((Object)ShippingTemplatesFree.class, (Object)criteria));
    }
    
    public void download(final List<ShippingTemplatesFreeDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final ShippingTemplatesFreeDto yxShippingTemplatesFree : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("省ID", yxShippingTemplatesFree.getProvinceId());
            map.put("模板ID", yxShippingTemplatesFree.getTempId());
            map.put("城市ID", yxShippingTemplatesFree.getCityId());
            map.put("包邮件数", yxShippingTemplatesFree.getNumber());
            map.put("包邮金额", yxShippingTemplatesFree.getPrice());
            map.put("计费方式", yxShippingTemplatesFree.getType());
            map.put("分组唯一值", yxShippingTemplatesFree.getUniqid());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public ShippingTemplatesFreeServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
